home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / RECORDS.SWG / 0009_Delete Record Routine.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  47 lines

  1. {
  2. DANIEL HEFLEY
  3.  
  4. > according to all references I've read, the only way to delete Records
  5. > in ANY File is to copy the good Records to a new File, skipping over
  6. > the ones you want deleted, delete the original File, and rename the new
  7. > one to the original name.  A long way of doing it, but I don't know of
  8. > any other.
  9.  
  10.  No.....You could:
  11. }
  12.  
  13. Procedure DelRec(RecIdx : LongInt);
  14. Var
  15.   Count,
  16.   RecNo : LongInt;
  17.   IFile : File of ItemRec;
  18.   Item : ItemRec;
  19.  
  20. begin
  21.   Assign(IFile,'Tmp.Dat'); Reset(f);   { assuming it exists }
  22.   Seek(IFile,idx);                     { assuming recidx exists }
  23.   RecNo := FileSize(f) - idx - 1;
  24.   For Count := idx to RecNo do
  25.   begin
  26.     Seek(IFile,Count+1);
  27.     Read(IFile,Item);        { read next rec }
  28.     Seek(IFile,Count);
  29.     Write(IFile,Item);       { overide prev rec }
  30.   end;
  31.   Seek(IFile,RecNo);                       { seek to last Record }
  32.   Truncate(IFile);                     { truncate rest of File }
  33.   Close(IFile);
  34. end;
  35.  
  36. {
  37. > Of course, you could cheat like I do...when I create a File With
  38. > Records, every one of them has one Boolean field called ACTIVE_REC,
  39. > which is forced to True when the Record is created.  if the user wants
  40. > to delete the Record, ACTIVE_REC becomes False and the Program ignores
  41. > the Record.  Eventually, you'll have to use the above
  42. > copy-delete-rename Procedure, but it sure saves time if you're just
  43. > deleting one Record!
  44.  
  45. When you initialize new Variables....find the Non Active Record and assign
  46. your File index Variable to that record!
  47. }